//
//  MTRechargeView.m
//  met
//
//  Created by 李晓俊 on 2019/8/7.
//  Copyright © 2019 李晓俊. All rights reserved.
//

#import "MTRechargeView.h"

@implementation MTRechargeView
{
    
    CGRect myframe;
    
}
- (MTRechargeView *)initWithFrame:(CGRect)frame

{
    self = [super initWithFrame:frame];
    if (self) {
        NSArray *nibs=[[NSBundle mainBundle]loadNibNamed:@"MTRechargeView" owner:nil options:nil];
        self=[nibs objectAtIndex:0];
        myframe = frame;
        
        
        self.bgView.userInteractionEnabled = YES;
        UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(remove)];
        [self.bgView addGestureRecognizer:tap];
        
    
        self.height.constant = 208 + BottomHeight ;
        [self needsUpdateConstraints];
        
        
        UIBezierPath *maskPath = [UIBezierPath bezierPathWithRoundedRect:CGRectMake(0, 0, kScreenWidth, 15) byRoundingCorners:UIRectCornerTopLeft | UIRectCornerTopRight cornerRadii:CGSizeMake(15, 15)];
        
        CAShapeLayer *maskLayer = [[CAShapeLayer alloc] init];
        maskLayer.frame = CGRectMake(0, 0, kScreenWidth, 15);
        maskLayer.path = maskPath.CGPath;
        
        self.backView.layer.mask = maskLayer;
        
        
        self.recharge1.userInteractionEnabled = YES;
        UITapGestureRecognizer *tap1 = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(recharge1Click)];
        [self.recharge1 addGestureRecognizer:tap1];
        
        self.recharge2.userInteractionEnabled = YES;
        UITapGestureRecognizer *tap2 = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(recharge2Click)];
        [self.recharge2 addGestureRecognizer:tap2];
        
        self.recharge3.userInteractionEnabled = YES;
        UITapGestureRecognizer *tap3 = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(recharge3Click)];
        [self.recharge3 addGestureRecognizer:tap3];
        
        self.recharge4.userInteractionEnabled = YES;
        UITapGestureRecognizer *tap4 = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(recharge4Click)];
        [self.recharge4 addGestureRecognizer:tap4];
        
    }
    return self;
}
-(void)drawRect:(CGRect)rect

{
    self.frame=myframe;//关键点在这里
}

- (void)remove {
    [self removeFromSuperview];
}
- (void)remove2 {
    [self removeFromSuperview];
}
- (IBAction)cancleClick:(id)sender {
    [self removeFromSuperview];
}
- (void)recharge1Click {
    if (self.rechargeDone) {
        self.rechargeDone(@"1");
    }
    [self removeFromSuperview];
}
- (void)recharge2Click {
    if (self.rechargeDone) {
        self.rechargeDone(@"2");
    }
    [self removeFromSuperview];
}
- (void)recharge3Click {
    if (self.rechargeDone) {
        self.rechargeDone(@"3");
    }
    [self removeFromSuperview];
}
- (void)recharge4Click {
    if (self.rechargeDone) {
        self.rechargeDone(@"4");
    }
    [self removeFromSuperview];
}

@end
